﻿using LibNiconico.NiconicoApi.Extentions;
using LibNiconico.NiconicoApi.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace LibNiconico.NiconicoApi.Alert
{
    /// <summary>
    /// ニコニコアラートログインレスポンス
    /// </summary>
    public class NicoAlertApiLoginResponse : NicoApiInfoXmlResponseBase<NicoAlertError>
    {

        /// <summary>
        /// 成功したか判定
        /// </summary>
        public new  bool Succeed
        {
            get
            {
                return this.Auth.IsSetAuth;
            }
        }

        internal NicoAlertApiLoginResponse(XDocument document) : base(document) { }

        internal NiconicoAlertAuth Auth { get; private set; }

        internal static NicoAlertApiLoginResponse Parse(XDocument document)
        {
            var response = new NicoAlertApiLoginResponse(document);
            response.Auth = new NiconicoAlertAuth(XElementExtention.GetElementAsString(document.Element("nicovideo_user_response"), "ticket"));
            return response;
        }

        /// <summary>
        /// エラーコード解析
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        protected override NicoAlertError ParseErrorCode(string code)
        {
            return NicoAlertError.Parse(code);
        }
    }
}
